//
//  RHLocalBatteryClusterFullChartVC.m
//  RuiHeApp
//
//  Created by bill on 2024/9/11.
//

#import "RHLocalBatteryClusterFullChartVC.h"
#import "AppDelegate.h"
#import "WSDatePickerView.h"
#import "RHLocalBatteryClusterChartView.h"

@interface RHLocalBatteryClusterFullChartVC ()
@property (nonatomic ,strong) RHLocalBatteryClusterChartView *chartView;

@property (nonatomic ,strong) RHLocalCellRealDataModel *chartModel;

@property (nonatomic ,strong) QMUILabel *titleLab;

@property (nonatomic ,strong) QMUIButton *backBtn;
@end

@implementation RHLocalBatteryClusterFullChartVC
- (instancetype)initWithModel:(RHLocalCellRealDataModel *)chartModel
{
    self = [super init];
    if (self) {

        self.chartModel = chartModel;
        self.chartModel.isAllowScale = YES;
        
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setupUI];
    
}

- (void)dealloc{
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:UIDeviceOrientationDidChangeNotification
                                                      object:nil];
}

- (void)setupUI{

    _chartView = [[RHLocalBatteryClusterChartView alloc] initWithFrame:CGRectMake(kSafe_top, 0,kUI_WINDOW_H - kSafe_top,kUI_WINDOW_W - kSafe_bottom) isLandscape:YES];

    [self.bgView addSubview:_chartView];
   
    [_chartView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsZero);
    }];

    _backBtn = [[QMUIButton alloc]init];
    [_backBtn setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
    [self.view addSubview:_backBtn];
    [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.width.height.offset(35);
        if(kSafe_top>20){
            make.top.mas_offset(15);
        }else{
            make.top.mas_offset(10);
        }
        
        
    }];
    kWeakSelf;
    [[_backBtn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        AppDelegate * delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
           delegate.allowRotate = 0;
        if(@available(iOS 16.0, *)) {
            [weakSelf.navigationController setNeedsUpdateOfSupportedInterfaceOrientations];
            NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
            UIWindowScene *ws = (UIWindowScene *)array[0];
            UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
            geometryPreferences.interfaceOrientations = UIInterfaceOrientationMaskPortrait;
            [ws requestGeometryUpdateWithPreferences:geometryPreferences errorHandler:^(NSError * _Nonnull error) {
                 //业务代码
            }];
        }else{
            NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
            [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];

        weakSelf.chartModel.isAllowScale = NO;
    }];
 
    [_chartView setChartModel:self.chartModel];
   
}



@end
